from flask import Flask
from flask_cors import CORS
from flask_jwt_extended import create_access_token, get_jwt_identity, jwt_required, JWTManager

from web.api.datafaker import datafaker_bp
from web.api.demo import demo_api_bp
from web.api.system import system_api_bp
from web.page.index import index_bp
from web.page.user import user_bp
from web.page.demo import amis_bp

jwt = JWTManager()


def create_flask_app() -> Flask:
    flask_app = Flask(
        __name__, template_folder="../../templates", static_folder="../../static"
    )

    flask_app.config["JWT_SECRET_KEY"] = "1234567981295"
    flask_app.config["JSON_AS_ASCII"] = False
    flask_app.config.update(DEBUG=True)

    jwt.init_app(flask_app)
    CORS(flask_app, origins="*")

    flask_app.register_blueprint(index_bp, url_prefix="/")
    flask_app.register_blueprint(amis_bp, url_prefix="/demo/amis")

    flask_app.register_blueprint(user_bp, url_prefix="/pages/user")

    flask_app.register_blueprint(system_api_bp, url_prefix="/api/")
    flask_app.register_blueprint(datafaker_bp, url_prefix="/api/datafaker")
    flask_app.register_blueprint(demo_api_bp, url_prefix="/api/demo")

    return flask_app
